package com.tobeface.wechat.message.handler;

import com.google.common.base.Objects;
import com.tobeface.wechat.message.WeChatMessage;
import com.tobeface.wechat.message.WeChatMessageChannel;
import com.tobeface.wechat.message.WeChatMessagePayloads;
import com.tobeface.wechat.message.WeChatMessageTypes;

/**
 * @author loudyn
 */
public abstract class LocationMessageHandlerSupport extends WeChatMessageHandlerSupport {

    @Override
    protected final boolean isMessageTypeSupport(String msgType, WeChatMessage message) {
        if (!Objects.equal(msgType, WeChatMessageTypes.LOCATION)) {
            return false;
        }
        return isLocationMessageSupport(message);
    }

    protected boolean isLocationMessageSupport(WeChatMessage message) {
        return true;
    }

    @Override
    protected void onMessageReceived(WeChatMessageChannel channel, WeChatMessage message) {
        String xpoint = (String) message.getPayloads().get(WeChatMessagePayloads.LOC_XPOINT_PAYLOAD);
        String ypoint = (String) message.getPayloads().get(WeChatMessagePayloads.LOC_YPOINT_PAYLOAD);
        String scale = (String) message.getPayloads().get(WeChatMessagePayloads.LOC_SCALE);
        String label = (String) message.getPayloads().get(WeChatMessagePayloads.LOC_LABEL);
        onLocationMessageReceived(channel, message, xpoint, ypoint, scale, label);
    }

    protected abstract void onLocationMessageReceived(WeChatMessageChannel channel, WeChatMessage message,
                                                      String xpoint, String ypoint,
                                                      String scale, String label);
}
